package com.tencreat.mall.controller.admin;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tencreat.domain.account.AppVersion;
import com.tencreat.service.account.IAppVersionService;
import com.tencreat.common.annotation.Log;
import com.tencreat.common.core.HttpResult;
import com.tencreat.common.core.controller.BaseController;
import com.tencreat.common.core.domain.AjaxResult;
import com.tencreat.common.core.domain.model.ReqIdParam;
import com.tencreat.common.enums.BusinessType;
import com.tencreat.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 【请填写功能名称】Controller
 *
 * @author mall
 * @date 2021-11-27
 */
@Api(tags="【请填写功能名称】api")
@RestController
@RequestMapping("/system/version")
public class AppVersionController extends BaseController {
    @Autowired
    private IAppVersionService appVersionService;

    /**
     * 查询【请填写功能名称】列表
     */
    @ApiOperation(value="查询【请填写功能名称】列表")
    @PreAuthorize("@ss.hasPermi('system:version:list')")
    @PostMapping("/list")
    public HttpResult<IPage<AppVersion>> list(@RequestBody AppVersion appVersion) {
        QueryWrapper<AppVersion> wrapper = Wrappers.query(appVersion);
        if (appVersion.getStartTime() != null && appVersion.getEndTime() != null){
            wrapper.between("create_time",appVersion.getStartTime(),appVersion.getEndTime());
        }
        Page<AppVersion> page =  new Page<>(appVersion.getPageNum(), appVersion.getPageSize());
        return HttpResult.ok(appVersionService.page(page, wrapper));
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @ApiOperation(value="导出【请填写功能名称】列表")
    @PreAuthorize("@ss.hasPermi('system:version:export')")
    @Log(title = "基础配置>版本配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public AjaxResult export(AppVersion appVersion) {
        List<AppVersion> list = appVersionService.selectAppVersionList(appVersion);
        ExcelUtil<AppVersion> util = new ExcelUtil<AppVersion>(AppVersion.class);
        return util.exportExcel(list, "version");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @ApiOperation(value="获取【请填写功能名称】详细信息")
    @PreAuthorize("@ss.hasPermi('system:version:query')")
    @PostMapping(value = "/getInfo")
    public HttpResult<AppVersion> getInfo(@RequestBody   ReqIdParam id) {
        return HttpResult.ok(appVersionService.selectAppVersionById(id));
    }

    /**
     * 新增【请填写功能名称】
     */
    @ApiOperation(value="新增【请填写功能名称】")
    @PreAuthorize("@ss.hasPermi('system:version:add')")
    @Log(title = "基础配置>版本配置", businessType = BusinessType.INSERT)
    @PostMapping(value = "/add")
    public HttpResult<Boolean> add(@RequestBody  AppVersion appVersion) {
        return to(appVersionService.insertAppVersion(appVersion));
    }

    /**
     * 修改【请填写功能名称】
     */
    @ApiOperation(value="修改【请填写功能名称】")
    @PreAuthorize("@ss.hasPermi('system:version:edit')")
    @Log(title = "基础配置>版本配置", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/edit")
    public HttpResult<Boolean> edit(@RequestBody  AppVersion appVersion) {
        return to(appVersionService.updateAppVersion(appVersion));
    }

    /**
     * 删除【请填写功能名称】
     */
    @ApiOperation(value="删除【请填写功能名称】")
    @PreAuthorize("@ss.hasPermi('system:version:remove')")
    @Log(title = "基础配置>版本配置", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    public HttpResult<Boolean> remove(@RequestBody ReqIdParam id) {
        return to(appVersionService.deleteAppVersionById(id));
    }
}
